//
//  UIView+CornerRadius.m
//  lvfj
//
//  Created by lvfeijun on 2021/7/6.
//  Copyright © 2021 Goudu KuaiEx Technology(Shenzhen)Co.,ltd. All rights reserved.
//

#import "UIView+CornerRadius.h"

@implementation UIView (CornerRadius)

-(void)setCornerRadius:(CGFloat)cornerRadius{
    self.layer.cornerRadius  = cornerRadius;
    self.layer.masksToBounds = YES;
}

- (UIView* (^)(CGFloat radius))hq_maskFloat
{
    return ^(CGFloat radius) {
        return [self hq_setRadius:radius];
    };
}

- (instancetype)hq_setRadius:(CGFloat)radius
{
    return [self hq_setRadius:radius corners:UIRectCornerAllCorners];
}
- (instancetype)hq_setRadius:(CGFloat)radius corners:(UIRectCorner)corners
{
    return [self hq_setRadius:radius rect:self.bounds corners:corners];
}
- (instancetype)hq_setRadius:(CGFloat)radius
                        rect:(CGRect)rect
                     corners:(UIRectCorner)corners
{
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
    
    //设置图形样子
    maskLayer.path = maskPath.CGPath;
    self.layer.mask= maskLayer;
    return self;
}

@end
